﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="my_htmlpiece.aspx.cs" Inherits="my_htmlpiece" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>我的邮件内容</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <link href="./css/ecrm03.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="./jquery/css/accordion.css" />

    <script language=javascript src="./js/Function.js"></script>
    <script language=javascript src="./js/myCheck.js"></script>
		<script type="text/javascript" src="./js/py.js"></script>    <script type="text/javascript" src="./jquery/autocomplete/lib/jquery.js"></script>

	<script type="text/javascript" src="./jquery/lib/chili-1.7.pack.js"></script>
	<script type="text/javascript" src="./jquery/lib/jquery.easing.js"></script>
	<script type="text/javascript" src="./jquery/lib/jquery.dimensions.js"></script>
	<script type="text/javascript" src="./jquery/jquery.accordion.js"></script>

	<script type="text/javascript" src="./jquery/tablesorter/jquery.tablesorter.js"></script>
	<link rel="stylesheet" href="./jquery/tablesorter/tablesorter.css" />
	
    <script type="text/javascript" language="javascript">
        //获取编辑器中HTML内容
        function getEditorHTMLContents(EditorName) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName); 
            return(oEditor.GetXHTML(true)); 
        }

        // 获取编辑器中文字内容
        function getEditorTextContents(EditorName) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName); 
            return(oEditor.EditorDocument.body.innerText); 
        }

        // 设置编辑器中内容
        function SetEditorContents(EditorName, ContentStr) { 
            var oEditor = FCKeditorAPI.GetInstance(EditorName) ; 
            oEditor.SetHTML(ContentStr) ; 
        }

        function switchaccordion0()
        {
            var accordions = jQuery('#lista');	        accordions.accordion("activate",0);        }

        function switchaccordion1()
        {
            var accordions = jQuery('#lista');	        accordions.accordion("activate",1);        }

        function piece_chk()
        {
			if(CheckText(form1.piecename,"名称",50)==false) return false;
			if(getEditorHTMLContents('fck_content')=='')
			{
				alert("内容不能空!");
				return false;
			}
			return true;
        }
        
        function piece_append()
        {
	        $.ajax({	            url:'./ajax/piece_append.ashx',	            type:'post',	            data: "piecename="+escape($("#piecename").val())+"&piececontent="+escape(getEditorHTMLContents("fck_content")),	            beforeSend:function()	            {	                return piece_chk();	            },	            error:function()	            {	                alert("保存失败！");	            },	            success: function()	            {	                piece_list();	                switchaccordion1();	                alert("保存成功！");	            }	        });        };
        
        function piece_save()
        {
	        $.ajax({	            url:'./ajax/piece_save.ashx',	            type:'post',	            data: "uid="+$("#pieceid").val()+"&piecename="+escape($("#piecename").val())+"&piececontent="+escape(getEditorHTMLContents("fck_content")),	            beforeSend:function()	            {	                return piece_chk();	            },	            error:function()	            {	                alert("保存失败！");	            },	            success: function()	            {	                piece_list();	                alert("保存成功！");	            }	        });        }
 	    	    function piece_remove(uid)	    {	        var surl='./ajax/piece_remove.ashx?uid='+uid;	        $.ajax({                url:surl,                type:'get',	            beforeSend:function()	            {	                if(confirm('删除操作不可恢复，确认吗？')==false) return false;	            },	            error:function()	            {	                alert('删除失败!');	            },                success:function()                {	                piece_list();                }	        });	    }	    	    function piece_get1(uid)	    {	        var urlstring='./ajax/piece_get1.ashx?uid='+uid+'&_='+(new Date()).getTime();	        $.ajax({	            url:urlstring,	            type:'get',	            dataType:'html',	            success: function(msg)	            {	                $("#piecename").val(msg);	            }	        });	    }	    	    function piece_get2(uid)	    {	        var urlstring='./ajax/piece_get2.ashx?uid='+uid+'&_='+(new Date()).getTime();	        $.ajax({	            url:urlstring,	            type:'get',	            dataType:'html',	            success: function(msg)	            {	                SetEditorContents('fck_content',msg);	            }	        });	    }	    	    function piece_get(uid)	    {	        $("#pieceid").val(uid);	        piece_get1(uid);	        piece_get2(uid);	        switchaccordion0();	    }       
	    function piece_list()	    {	        var urlstring='./ajax/piece_list.ashx';	        	        $.ajax({	            url:urlstring,	            type:'get',	            data: "_=" + (new Date()).getTime(),	            dataType:'html',	            beforeSend:function()	            {	                $("#piecelist").empty().append("<img id='loading' src='./images/loading2.gif' />loading...");	            },	            error:function()	            {	                $("#piecelist").empty().append('数据读取失败！');	            },	            success: function(msg)	            {	                $("#piecelist").empty().append(msg);	                $("#pieces").tablesorter({widthFixed: true, widgets: ['zebra'],headers:{2:{sorter:false}}});	            }	        });	    }       
	    function email_list()	    {	        var urlstring='./ajax/get_sendemail.ashx';	        	        $.ajax({	            url:urlstring,	            type:'get',	            data: "_=" + (new Date()).getTime()+"&ssql="+escape($("#sqlcommand").val()),	            dataType:'html',	            beforeSend:function()	            {	                $("#emails").empty().append("&nbsp;&nbsp;<img id='loading' src='./images/loading2.gif' />loading...");	            },	            error:function()	            {	                $("#emails").empty().append('&nbsp;&nbsp;数据读取失败！');	            },	            success: function(msg)	            {	                $("#emails").empty().append(msg);	            }	        });	    }
		function ischkall()
		{
			for(var i = 0; i < form1.elements.length; i++)
			{
				if(form1.elements[i].type=='checkbox')
				{
					form1.elements[i].checked=form1.chkall.checked;
				}
			}
		}
	    	    function sendmail(puid,email)	    {	        var urlstring='./ajax/sendmail.ashx';	        	        $.ajax({	            url:urlstring,	            data: "puid=" + puid+"&email="+escape(email)	        });	    }	    	    function runsend()	    {			if(confirm('确认要给选中的联系人发送邮件吗?'))
			{
			    var puid=$("#pieceid").val();
    			
                $("#sending").empty().append("&nbsp;&nbsp;<img id='loading' src='./images/loading2.gif' />sending...");    			
			    for(var i = 0; i < form1.elements.length; i++)
			    {
				    if(form1.elements[i].type=='checkbox')
				    {
					    if(form1.elements[i].checked)
					    {
                            if(form1.elements[i].name!='chkall')
                            {
                                var email=form1.elements[i].value;
                                
                                if(CheckEMailStr(email))
                                {
                                    sendmail(puid,email);
                                }
                            }
					    }
				    }
			    }
	            $("#sending").empty().append("send ok!");	        }	    }	    	    function piece_clear()	    {	        $("#pieceid").val('');	        $("#piecename").val('');	        SetEditorContents('fck_content','');	        $("#piecename").focus();	    }    
	    $(document).ready(function(){	        piece_list();	        jQuery('#lista').accordion();	    });    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="900" border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td style="font-weight: bold; font-size: 10pt;">
                    <div id="nav"><a href="index.aspx"><span>首页</span></a><a class="now" href="my_ecrm.aspx"><span>我的名片夹</span></a><a href="my_givelist.aspx"><span>我的赠刊名录</span></a><a href="my_plan.aspx"><span>我的周计划</span></a><a href="employee2.aspx"><span>员工联系表</span></a></div>
                    <div class="clear"></div><div id="status"><div id="subnav"></div><span class="pl"><asp:Literal ID="userstatus1" runat="server"></asp:Literal><asp:Literal ID="userstatus2" runat="server"></asp:Literal></span></div>
                    <div><h1><asp:Literal ID="bigname0" runat="server"></asp:Literal>的邮件内容</h1></div>
                     <div class="basic" id="lista">
                         <a>&nbsp;邮件内容</a>
                        <div>
                            <p style="text-align: center;">
                                <table border="1" cellpadding="2" cellspacing="0" style='BORDER-COLLAPSE: collapse' bordercolor="#cfdfff" width="96%" align="center">
                                    <tr>
                                        <td align="right">邮件内容名称</td><td align="left"><asp:TextBox ID="piecename" runat="server" Width="580px"></asp:TextBox>(50个汉字)</td>
                                    </tr>
                                    <tr>
                                        <td colspan=2><FCKeditorV2:FCKeditor ID="fck_content" runat="server" BasePath="/easycrm/fckeditor/" Height="450px" Width="100%" ToolbarSet="CMS01"></FCKeditorV2:FCKeditor></td>
                                    </tr>
                                    <tr>
                                        <td colspan=2><input id="btnNew" type="button" onclick="piece_append()" value="保存新内容" style="width: 100px;" />&nbsp;<input id="btnSave" type="button" onclick="piece_save()" value="保存修改" style="width: 100px;" />&nbsp;<input id="btnReset" type="button" value="重新填写" style="width: 100px;" onclick="piece_clear()" /></td>
                                    </tr>
                                </table>
                            </p>
                        </div>
                        <a>&nbsp;我的内容列表...</a>
                        <div>
                            <div id="piecelist"></div>
                        </div>
                    </div><br />
                    <div>
                       <!-- 
                        <table border="1" cellpadding="2" cellspacing="0" style='BORDER-COLLAPSE: collapse' bordercolor="#cfdfff" width="98%">
                            <tr height="30">
                                <td>
                                    <div id="sqlcmd">
                                        &nbsp;&nbsp;<font style="font-size: 10pt; font-weight: normal;">筛选语句:</font><input type="text" id="sqlcommand" name="sqlcommand" size="70" value="select * from t_linkman where email<>''" /><input type="button" value="筛选" onclick="email_list()" /><input type="button" value="发送" onclick="runsend()" /><span id="sending" name="sending"></span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="emails">
                                    </div>
                                </td>
                            </tr>
                        </table>
                        -->
                    </div><br />
                    <div style="border-bottom: darkgray 1px solid;"></div>
                    <span class="bottomfont">SEEC&copy; 2008-2009 汽车中国</span>
                </td>
            </tr>
        </table>
	    <div id="myhidediv" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; VISIBILITY: hidden; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; HEIGHT: 1px"><asp:TextBox id="pieceid" runat="server"></asp:TextBox></div>
    </div>
    </form>
</body>
</html>
